package robotleMvc.ui.lizhi.fensan
{
	import _Pan3D.core.MathTween;
	
	import flash.display3D.Context3D;
	import flash.display3D.Context3DProgramType;
	import flash.display3D.Context3DVertexBufferFormat;
	import flash.geom.Matrix3D;
	import flash.geom.Vector3D;
	
	public class FensanBiandaDisplaySprite extends FensanDisplaySprite
	{
		private var _colorVector3D:Vector3D;
		public function FensanBiandaDisplaySprite(context:Context3D)
		{
			super(context);
		}
		override protected function initLizhiData():void
		{
			var context3D:Context3D=_context;
			var _triNum:Number=360/2;
			_triNum=100
			var _pArr:Array=new Array;
			var _mArr:Array=new Array;
			var _iArr:Array=new Array;
			var _w:Number=30;
			var _h:Number=10;
			for(var i:int=0;i<_triNum;i++){
				var zz:Number=0;
				_pArr.push(0, _h, zz, 0,0, 1);
				_pArr.push(_w*2, _h, zz, 1,0, 1);
				_pArr.push(_w*2, -_h, zz, 1,1, 1);
				_pArr.push(0, -_h, zz, 0,1, 1);
				var a:Number=0;
				var b:Number= Math.random()*360*Math.PI/180;
				var c:Number= Math.random()*360*Math.PI/180;
				_mArr.push(a,b,c);
				_mArr.push(a,b,c);
				_mArr.push(a,b,c);
				_mArr.push(a,b,c);
				var n:int=i*4;
				_iArr.push(n+0,n+1,n+2);
				_iArr.push(n+0,n+2,n+3);
			}
			lizhiVertexBuffer  = context3D.createVertexBuffer( _triNum*4, 6);
			lizhiVertexBuffer.uploadFromVector(Vector.<Number>(_pArr), 0, _pArr.length/6);
			lizhiStateVertexBuffer  = context3D.createVertexBuffer( _triNum*4, 3);
			lizhiStateVertexBuffer.uploadFromVector(Vector.<Number>(_mArr), 0, _mArr.length/3);
			lizhiIndexBuffer  = context3D.createIndexBuffer(_iArr.length);
			lizhiIndexBuffer.uploadFromVector(Vector.<uint>(_iArr), 0, _iArr.length);
			
			_colorVector3D=new Vector3D(Math.random(),Math.random(),Math.random(),Math.random());
		}
		override protected function setVa() : void {
			if(!lizhiIndexBuffer){
				initLizhiData();
				return;
			}
			_context.setVertexBufferAt(0,lizhiVertexBuffer, 0, Context3DVertexBufferFormat.FLOAT_3);
			_context.setVertexBufferAt(1,lizhiVertexBuffer, 3, Context3DVertexBufferFormat.FLOAT_3);
			_context.setVertexBufferAt(2,lizhiStateVertexBuffer, 0, Context3DVertexBufferFormat.FLOAT_3);
			_context.setTextureAt(0, _objData.texture);
			//_context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT,0,Vector.<Number>( [ 2,2,2,0.1])); 
			_context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT,0,Vector.<Number>( [ _colorVector3D.x,_colorVector3D.y,_colorVector3D.z,_colorVector3D.w])); 
			_context.drawTriangles(lizhiIndexBuffer, 0, -1);
		}
		override protected function resetVa() : void {
			_context.setVertexBufferAt(0, null);
			_context.setVertexBufferAt(1, null);
			_context.setVertexBufferAt(2, null);
			_context.setTextureAt(0,null);
		}
		override protected function setVc() : void {
			this.updateMatrix();
			_context.setProgramConstantsFromMatrix(Context3DProgramType.VERTEX, 4, modelMatrix, true);
			var vectorData : Vector.<Number>=new Vector.<Number>;
			_timer++;
			var t:Number=MathTween.easeIn(_timer%10,0,100,10);
			var b:Number=0;
			var c:Number=0;
			var d:Number=0;
			vectorData.push(t, 1, 0, 0,b, 0, 0, 0, c, 0,0, 0, d, 0, 0, 0);
			var dataMatrix : Matrix3D = new Matrix3D(vectorData);
			_context.setProgramConstantsFromMatrix(Context3DProgramType.VERTEX, 8, dataMatrix, true);  //这里暂可以传一个时间进去;
		}
		
	}
}